home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TransSkel.cpt / Skel.pas < prev    next >
Pascal/Delphi Source File  |  1987-01-07  |  5KB  |  194 lines

  1.  
  2. {    TransSkel demonstration:  Traditional Skel}
  3.  
  4. {    This program mimics the original Skel application:  one sizable,}
  5. {    dragable, non-closable dark gray window, an "About" alert and two}
  6. {    dialogs.  Desk accessories supported.}
  7.  
  8. {    The project should include this file, TransSkelPas (or a project}
  9. {    built from TransSkel.c),MacPasLib, and MacTraps.}
  10.  
  11. {    27 June 1986        Paul DuBois}
  12. {    1 January 1987    Ωhm Software - port to LS Pascal    }
  13.  
  14. PROGRAM Skel;
  15.  
  16.     USES
  17.         TransSkelPas;
  18.  
  19.     CONST
  20. {    Resource numbers}
  21.  
  22.         fileMenuRes = 2;        { File menu }
  23.         AboutAlrt = 1000;    { About box }
  24.         theWindRes = 260;        { window }
  25.         reportDlog = 257;        { message dialog box }
  26.         aboutStr = 1;        { message strings }
  27.         rattleStr = 2;
  28.         frightStr = 3;
  29.  
  30. { file menu item numbers }
  31.  
  32.         rattle = 1;
  33.         frighten = 2;
  34.         quit = 4;
  35.  
  36.     TYPE
  37.         EventPtr = ^EventRecord;
  38.  
  39.     VAR
  40.         theWind : WindowPtr;
  41.  
  42. {    Menu handles.  There isn't any apple menu here, since TransSkel will}
  43. {    be told to handle it itself.}
  44.  
  45.         fileMenu : MenuHandle;
  46.  
  47. { -------------------------------------------------------------------- }
  48. {                        Menu handling procedures                        }
  49. { -------------------------------------------------------------------- }
  50.  
  51. {    Read a string resource and put into the Alert/Dialog paramtext}
  52. {    values}
  53.  
  54.     PROCEDURE SetParamText (strNum : integer);
  55.  
  56.         VAR
  57.             h : StringHandle;
  58.  
  59.     BEGIN
  60.         h := GetString(strNum);
  61.         HLock(Handle(h));
  62.         ParamText(h^^, '', '', '');
  63.         HUnlock(Handle(h));
  64.     END;
  65.  
  66. {    Handle selection of "About Skel…" item from Apple menu}
  67.  
  68.     PROCEDURE DoAbout;
  69.  
  70.         VAR
  71.             h : StringHandle;
  72.             ignore : integer;
  73.  
  74.     BEGIN
  75.         SetParamText(aboutStr);
  76.         ignore := Alert(aboutAlrt, NIL);
  77.     END;
  78.  
  79. {    Put up a dialog box with a message and an OK button.  The message}
  80. {    is stored in the 'STR ' resource whose number is passed as strNum.}
  81.  
  82.     PROCEDURE report (strNum : integer);
  83.  
  84.         VAR
  85.             theDialog : DialogPtr;
  86.             itemHit : integer;
  87.  
  88.     BEGIN
  89.         SetParamText(strNum);
  90.         theDialog := GetNewDialog(Integer(reportDlog), Ptr(NIL), WindowPtr(-1));
  91.         ModalDialog(NIL, itemhit);
  92.         DisposDialog(theDialog);
  93.     END;
  94.  
  95. {    Process selection from File menu.}
  96.  
  97. {    Rattle, Frighten    A dialog box with message}
  98. {    Quit    Request a halt by calling SkelHalt().  This makes SkelMain}
  99. {            return.}
  100.  
  101.     PROCEDURE DoFileMenu (item : integer);
  102.  
  103.     BEGIN
  104.         CASE item OF
  105.             rattle : 
  106.                 Report(rattleStr);
  107.             frighten : 
  108.                 Report(frightStr);
  109.             quit : 
  110.                 SkelWhoa;
  111.             OTHERWISE
  112.                 ;
  113.         END;
  114.     END;
  115.  
  116.  
  117. {    Initialize menus.  Tell TransSkel to process the Apple menu}
  118. {    automatically, and associate the proper procedures with the}
  119. {    File and Edit menus.}
  120.  
  121.     PROCEDURE SetUpMenus;
  122.  
  123.     BEGIN
  124.         SkelApple('About Skel...', @DoAbout);
  125.         fileMenu := GetMenu(fileMenuRes);
  126.         SkelMenu(fileMenu, @DoFileMenu, NIL);
  127.     END;
  128.  
  129. { -------------------------------------------------------------------- }
  130. {                    Window handling procedures                            }
  131. { -------------------------------------------------------------------- }
  132.  
  133.     PROCEDURE WindActivate (active : Boolean);
  134.  
  135.     BEGIN
  136.         DrawGrowIcon(theWind);    { make grow box reflect new window state }
  137.     END;
  138.  
  139. {    On update event, can ignore the resizing information, since the whole}
  140. {    window is always redrawn in terms of the current size, anyway.}
  141. {    Content area is dark gray except scroll bar areas, which are white.}
  142. {    Draw grow box as well.}
  143.  
  144.     PROCEDURE WindUpdate (resized : Boolean);
  145.  
  146.         VAR
  147.             r : Rect;
  148.  
  149.     BEGIN
  150.         r := theWind^.portRect;        { paint window dark gray }
  151.         r.bottom := r.bottom - 15;            { don't bother painting the }
  152.         r.right := r.right - 15;            { scroll bar areas }
  153.         FillRect(r, dkGray);
  154.         r := theWind^.portRect;    { paint scroll bar areas white }
  155.         r.left := r.right - 15;
  156.         FillRect(r, white);
  157.         r := theWind^.portRect;
  158.         r.top := r.bottom - 15;
  159.         FillRect(r, white);
  160.         DrawGrowIcon(theWind);
  161.     END;
  162.  
  163.     PROCEDURE WindHalt;
  164.  
  165.     BEGIN
  166.         CloseWindow(theWind);
  167.     END;
  168.  
  169. {    Read window from resource file and install handler for it.  Mouse}
  170. {    and key clicks are ignored.  There is no close proc since the window}
  171. {    doesn't have a close box.  There is no idle proc since nothing is}
  172. {    done while the window is in front (all the things that are done are}
  173. {    handled by TransSkel).}
  174.  
  175.     PROCEDURE WindInit;
  176.  
  177.     BEGIN
  178.         theWind := GetNewWindow(theWindRes, NIL, WindowPtr(-1));
  179.         SetPort(theWind);
  180.         SkelWindow(theWind, NIL, NIL, @WindUpdate, @WindActivate, NIL, @WindHalt, NIL, false);
  181.     END;
  182.  
  183. { -------------------------------------------------------------------- }
  184. {                                    Main                                }
  185. { -------------------------------------------------------------------- }
  186.  
  187.  
  188. BEGIN
  189.     SkelInit;                { initialize }
  190.     SetUpMenus;                { install menu handlers }
  191.     WindInit;                    { install window handler }
  192.     SkelMain;                { loop 'til Quit selected }
  193.     SkelClobber;                { clean up }
  194. END.